package com.vjwealth.android.nos.base

import android.support.v7.widget.LinearLayoutManager
import com.andview.refreshview.XRefreshView
import com.vjwealth.android.nos.java.widget.XRefreshFooter
import com.vjwealth.android.nos.java.widget.XRefreshHeader
import kotlinx.android.synthetic.main.layout_refresh_recycler.*

abstract class BaseXRefreshRecyclerActivity : BaseActivity() {

    protected var mXRefreshFooter: XRefreshFooter? = null
    protected var mXRefreshHeader: XRefreshHeader? = null
    protected var mLayoutManager: LinearLayoutManager? = null

    override fun setContentView(layoutResID: Int) {
        super.setContentView(layoutResID)
        mXRefreshHeader = XRefreshHeader(this@BaseXRefreshRecyclerActivity)
        mXRefreshFooter = XRefreshFooter(this@BaseXRefreshRecyclerActivity)
        mLayoutManager = LinearLayoutManager(this@BaseXRefreshRecyclerActivity)
        setXRefreshView()

        mRecyclerView.setHasFixedSize(true)
        initRecyclerView()
    }

    private fun setXRefreshView(){
        mXRefreshView.setCustomFooterView(mXRefreshFooter)
        mXRefreshView.setCustomHeaderView(mXRefreshHeader)
        mXRefreshView.setPinnedTime(600)
        mXRefreshView.setMoveForHorizontal(true)
        mXRefreshView.setPullLoadEnable(false)
        mXRefreshView.setAutoLoadMore(false)
        mXRefreshView.enableReleaseToLoadMore(true)
        mXRefreshView.enableRecyclerViewPullUp(true)
        mXRefreshView.enablePullUpWhenLoadCompleted(true)
        mXRefreshView.setXRefreshViewListener(object : XRefreshView.SimpleXRefreshListener(){
            override fun onRefresh(isPullDown: Boolean) {
                onRecyclerRefresh(isPullDown)
            }

            override fun onLoadMore(isSilence: Boolean) {
                onRecyclerLoadMore(isSilence)
            }
        })
    }

    abstract fun onRecyclerRefresh(isPullDown: Boolean)

    abstract fun onRecyclerLoadMore(isSilence: Boolean)

    abstract fun initRecyclerView()
}
